home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
utility.lha
/
utility
/
statcount.H
< prev
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
2KB
|
64 lines
// StatCount is a class for simple statistics gathering in C++ programs.
// Integer values are counted in equal-sized bins during the lifetime
// of the StatCount object. The values of the bins are printed when the
// object is destroyed.
//
// Statcount uses the stdio library and does not depend on intialization
// of C++ i/o streams. It can therefore be used in constructors and
// destructors of static objects.
//
// .SS Example
// .nf
// void f(int x) {
// static StatCount cnt("Arguments to f", 0, 100, 10);
// cnt(x);
// ....
// }
//
// .SS Author
// Dag Bruck
//
// $Id: statcount.H,v 1.1 91/09/06 12:01:49 dag Exp $
#ifndef STATCOUNT_H
#define STATCOUNT_H
class StatCount {
public:
StatCount(const char* t, int min, int max, unsigned res);
// Creates a statistics counter with given title, range and resolution.
// The range of the counters is [min, max[.
// The title is copied internally.
void operator () (int x);
// Registers the value of `x' in the appropriate counter. A value outside
// the range given to the constructor will be registered in the first or
// last counter.
void Dump() const;
// Prints the contents of the counters on standard error output,
// preceded by the title given to the constructor.
~StatCount();
// Calls Dump() and frees allocated storage.
private:
char* title;
// Title of print-out.
int min;
unsigned res;
// Minimum value and resolution.
unsigned n;
// Number of counters.
unsigned* v;
// Array of counters.
};
#endif